package gui;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.Scrollable;

import java.awt.GridBagLayout;
import javax.swing.JMenuBar;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.util.Observer;

import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;

import observer.Broker;

import navigatore.AgenteNavigatore;

public class MainPanel extends JPanel implements Scrollable,observer.Observer{
	
	private JMenuBar menuBar;
	private JMenu file,report;
	private JMenuItem provaItem;
	private Broker broker;
	
	private MapPanel mapPanel;
	private LeftPanel leftPanel;
	
	private JScrollPane scrollMap;
	
	public MainPanel() {
		
		this.broker = new Broker();
		
		setLayout(new BorderLayout(0, 0));
		
		setBorder(new LineBorder(new Color(0, 0, 0), 2, true));
				
		this.setSize(900, 600);
				
		menuBar = new JMenuBar();
		provaItem = new JMenuItem("Prova");
		
		file = new JMenu("File");
		report = new JMenu("Statistiche dati");
		
		
		file.add(provaItem);
		
		menuBar.add(file);
		menuBar.add(report);
		
		add(menuBar,BorderLayout.NORTH);
		
		mapPanel = new MapPanel(broker);
		
		scrollMap = new JScrollPane(mapPanel);
		scrollMap.setViewportView(mapPanel);
		scrollMap.setPreferredSize(new Dimension(500, 500));
		scrollMap.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollMap.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		scrollMap.getVerticalScrollBar().setUnitIncrement(1);
		
		scrollMap.setVisible(true);
		
		add(scrollMap, BorderLayout.CENTER);
		
		leftPanel = new LeftPanel(broker);
		add(leftPanel, BorderLayout.WEST);
		// TODO Auto-generated constructor stub
	}

	@Override
	public Dimension getPreferredScrollableViewportSize() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getScrollableBlockIncrement(Rectangle visibleRect,
			int orientation, int direction) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean getScrollableTracksViewportHeight() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean getScrollableTracksViewportWidth() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int getScrollableUnitIncrement(Rectangle visibleRect,
			int orientation, int direction) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void update(Object object) {
		// TODO Auto-generated method stub
		if(object.equals("repaintMapPanel")){
			this.repaint();
		}
		
	}

}
